package com.yusi.controller;


import com.yusi.entity.FlightMana;
import com.yusi.entity.dto.RespBean;
import com.yusi.entity.dto.RespPageBean;
import com.yusi.service.IFlightManaService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yusi
 * @since 2022-01-06
 */
@RestController
@RequestMapping("/air/info")
public class FlightManaController {

    @Autowired
    IFlightManaService iFlightManaService;
    @ApiOperation("获取所有的航班")
    @GetMapping("/airPort/")
    public RespPageBean getAirPort(@RequestParam(defaultValue = "1")Integer currentpage,
                                   @RequestParam(defaultValue = "10")Integer size,
                                   String input,
                                   FlightMana flightMana,
                                   LocalDate[] beginDateScope){
        return iFlightManaService.getAirPort(currentpage,size,input,flightMana,beginDateScope);
    }

    @ApiOperation("新增航班")
    @PostMapping("/airPort")
    public RespBean saveAirPort(@RequestBody FlightMana flightMana){
        System.out.println(flightMana);
       return iFlightManaService.saveAirPort(flightMana);
    }

    @ApiOperation("删除航班")
    @DeleteMapping("/airPort/{id}")
    @Transactional
    public RespBean delAirPort(@PathVariable Integer id){
        System.out.println(id);
        if (iFlightManaService.removeById(id)){
            return RespBean.success("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation("修改航班")
    @PutMapping("/airPort")
    @Transactional
    public RespBean updAirPort(@RequestBody FlightMana flightMana){
        if (iFlightManaService.updateById(flightMana)){
            return RespBean.success("修改成功！");
        }
        return RespBean.error("修改失败！");
    }

//    @ApiOperation("获取所有的航班")
//    @GetMapping("/airPort/")
//    public RespPageBean getAirPort(@RequestParam(defaultValue = "1")Integer currentpage,
//                                   @RequestParam(defaultValue = "10")Integer size,
//                                   FlightMana flightMana,
//                                   LocalDate[] beginDateScope){
//        return iFlightManaService.getAirPort(currentpage,size,flightMana,beginDateScope);
//    }



}
